﻿namespace QASPRibbon.Controls
{
    /// <summary>
    /// Definition for image, which is embedded into button or another ribbon control.
    /// </summary>
    public class RibbonImageDefinition
    {
        /// <summary>
        /// Url for 32x32 image thumbnail
        /// </summary>
        public string Url32 { get; set; }

        /// <summary>
        /// Url for 16x16 image thumbnail
        /// </summary>
        public string Url16 { get; set; }

        /// <summary>
        /// X-coordinate for composite images (for example, for OOTB formatmap.png)
        /// </summary>
        public int? X { get; set; }

        /// <summary>
        /// Y-coordinate for composite images (for example, for OOTB formatmap.png)
        /// </summary>
        public int? Y { get; set; }

        ///<summary>
        /// Creates an empty instance of RibbonImageDefinition class
        ///</summary>
        public RibbonImageDefinition()
        {
            Url32 = string.Empty;
            Url16 = string.Empty;
        }

        internal int UIVersion = 14;

        /// <summary>
        /// <para>Returns ImageDefinition for standard image formatmap32x32.png &amp; formatmap16x16.png.</para>
        /// <para>Caution: if you have non-english SharePoint installation, and don't have English language pack,
        /// this will not work. Use overload with 3 parameters.</para>
        /// </summary>
        /// <param name="x">X-coordinate of image thumbnail on composite image</param>
        /// <param name="y">Y-coordinate of image thumbnail on composite image</param>
        /// <returns>ImageDefinition instanse for standard image with specified coordinates</returns>
        public static RibbonImageDefinition Standard(int x, int y)
        {
            return new RibbonImageDefinition
            {
                Url16 = "/_layouts/1033/images/formatmap16x16.png",
                Url32 = "/_layouts/1033/images/formatmap32x32.png",
                X = x,
                Y = y
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static RibbonImageDefinition Standard15(int x, int y)
        {
            return new RibbonImageDefinition
            {
                Url16 = "/_layouts/15/1033/images/formatmap16x16.png",
                Url32 = "/_layouts/15/1033/images/formatmap32x32.png",
                X = x,
                Y = y,
                UIVersion = 15,
                _isStandard = true
            };
        }

        /// <summary>
        /// <para>Returns ImageDefinition for standard image formatmap32x32.png &amp; formatmap16x16.png.</para>
        /// </summary>
        /// <param name="x">X-coordinate of image thumbnail on composite image</param>
        /// <param name="y">Y-coordinate of image thumbnail on composite image</param>
        /// <param name="lcid">Locale ID of current web</param>
        /// <returns>ImageDefinition instanse for standard image with specified coordinates</returns>
        public static RibbonImageDefinition Standard(int x, int y, int lcid)
        {
            return new RibbonImageDefinition
            {
                Url16 = string.Format("/_layouts/{0}/images/formatmap16x16.png", lcid),
                Url32 = string.Format("/_layouts/{0}/images/formatmap32x32.png", lcid),
                X = x,
                Y = y
            };
        }

        /// <summary>
        /// <para>Returns ImageDefinition for standard image formatmap32x32.png &amp; formatmap16x16.png.</para>
        /// </summary>
        /// <param name="x">X-coordinate of image thumbnail on composite image</param>
        /// <param name="y">Y-coordinate of image thumbnail on composite image</param>
        /// <param name="lcid">Locale ID of current web</param>
        /// <returns>ImageDefinition instanse for st4andard image with specified coordinates</returns>
        public static RibbonImageDefinition Standard15(int x, int y, int lcid)
        {
            return new RibbonImageDefinition
            {
                Url16 = string.Format("/_layouts/15/{0}/images/formatmap16x16.png", lcid),
                Url32 = string.Format("/_layouts/15/{0}/images/formatmap32x32.png", lcid),
                X = x,
                Y = y,
                UIVersion = 15,
                _isStandard = true
            };
        }

        private bool _isStandard;

        internal int Position16X
        {
            get
            {
                if (!X.HasValue) return 0;
                if (!_isStandard) return X.Value;
                if (UIVersion == 15) return -((X.Value*18) + 1);
                return -(X.Value * 16);
            }
        }

        internal int Position32X
        {
            get
            {
                if (!X.HasValue) return 0;
                if (!_isStandard) return X.Value;
                if (UIVersion == 15) return -((X.Value * 34) + 1);
                return -(X.Value * 32);
            }
        }

        internal int Position16Y
        {
            get
            {
                if (!Y.HasValue) return 0;
                if (!_isStandard) return Y.Value;
                if (UIVersion == 15) return -((Y.Value * 18) + 1);
                return -(Y.Value * 16);
            }
        }

        internal int Position32Y
        {
            get
            {
                if (!Y.HasValue) return 0;
                if (!_isStandard) return Y.Value;
                if (UIVersion == 15) return -((Y.Value * 34) + 1);
                return -(Y.Value * 32);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public static class Hive32
        {
            /// <summary>
            /// 
            /// </summary>
            public static RibbonImageDefinition ActionsCreate = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/actionscreate.jpg",
                    X = 0,
                    Y = 0
                };

            /// <summary>
            /// 
            /// </summary>
            public static class CenterAdmin
            {
                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition Databases = new RibbonImageDefinition
                    {
                        Url16 = string.Empty,
                        Url32 = "/_layouts/images/centraladmin_applicationmanagement_databases_32x32.png",
                        X = 0,
                        Y = 0
                    };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition ServiceApplication = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_applicationmanagement_serviceapplications_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition SiteCollcetions = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_applicationmanagement_sitecollections_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition BackupAndRestore = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_backupandrestore_farmbackupandrestore_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition BackupAndRestoreGranular = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_backupandrestore_granularbackup_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition FarmConfiguration = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_configurationwizards_farmconfiguration_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition ContentDeployment = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_generalapplicationsettings_contentdeployment_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition ExternalServiceConnections = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_generalapplicationsettings_externalserviceconnections_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition SiteDirectory = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_generalapplicationsettings_sitedirectory_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition HealthStatus = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_monitoring_healthstatus_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition Reporting = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_monitoring_reporting_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition TimerJobs = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_monitoring_timerjobs_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition GeneralSecurity = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_security_generalsecurity_32x32.png",
                    X = 0,
                    Y = 0
                };

                /// <summary>
                /// 
                /// </summary>
                public static readonly RibbonImageDefinition InformationPolicy = new RibbonImageDefinition
                {
                    Url16 = string.Empty,
                    Url32 = "/_layouts/images/centraladmin_security_informationpolicy_32x32.png",
                    X = 0,
                    Y = 0
                };
            }
        }
    }
}
